package fr.cnam.projetSiw.widget;

import java.util.ArrayList;

import com.google.gwt.user.client.ui.FocusPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

import fr.cnam.projetSiw.widget.ressources.WidgetBundle;

public class PhotoSquare extends HorizontalPanel
{
	
	public PhotoSquare()
	{
		super();
		this.addStyleName(WidgetBundle.INSTANCE.cssSquare().photoSquare());
	}

	public void addSquareTrack(String urlImg, String artistName, String date, String trackName)
	{
		addSquare(urlImg);
		
		
		VerticalPanel pnlInfos = new VerticalPanel();
		
		pnlInfos.addStyleName(WidgetBundle.INSTANCE.cssSquare().pnlInfos());
		
		Label lblTrackName = new Label(trackName);
		lblTrackName.addStyleName(WidgetBundle.INSTANCE.cssSquare().titleInfo());

		Label lblArtistName = new Label(artistName);
		lblArtistName.addStyleName(WidgetBundle.INSTANCE.cssSquare().linkInfo());

		Label lblsubName = new Label(date);
		lblsubName.addStyleName(WidgetBundle.INSTANCE.cssSquare().subInfo());
		
		pnlInfos.add(lblTrackName);
		pnlInfos.add(lblArtistName);
		pnlInfos.add(lblsubName);
		

		add(pnlInfos);
		
		
		
	}
	
	public FocusPanel addSquareArtiste(String urlImg, String artistName, String date, ArrayList<String> genres)
	{
		FocusPanel pnlImg = addSquare(urlImg);

		VerticalPanel pnlInfos = new VerticalPanel();

		pnlInfos.addStyleName(WidgetBundle.INSTANCE.cssSquare().pnlInfos());

		Label lblArtistName = new Label(artistName);
		lblArtistName.addStyleName(WidgetBundle.INSTANCE.cssSquare().titleInfo());

		pnlInfos.add(lblArtistName);

		if (genres != null)
		{
			HorizontalPanel pnl = new HorizontalPanel();
			int cpt = 0;
			for (String genre : genres)
			{
				if (cpt == 2)
					break;
				Label lblGenre = new Label(genre);
				lblGenre.addStyleName(WidgetBundle.INSTANCE.cssSquare().linkInfo());

				if (cpt == 0 && genres.size() > 1)
				{
					lblGenre.setText(lblGenre.getText() + " - ");
				}
				pnl.add(lblGenre);
				cpt++;
			}
			pnlInfos.add(pnl);
		}


		Label lblsubName = new Label(date);
		lblsubName.addStyleName(WidgetBundle.INSTANCE.cssSquare().subInfo());


		pnlInfos.add(lblsubName);

		add(pnlInfos);

		return pnlImg;
	}

	private FocusPanel addSquare(String urlImg)
	{
		FocusPanel pnlImg = new FocusPanel();
		
		pnlImg.addStyleName(WidgetBundle.INSTANCE.cssSquare().square());
		//TODO gros caca
		pnlImg.getElement().getStyle().setBackgroundImage("url("+ urlImg + ")");
		add(pnlImg);

		return pnlImg;
	}
}
